package cn.hsw.platform.controller;

import cn.hsw.platform.core.doc.annotation.AuthPermission;
import cn.hsw.platform.core.doc.contants.AuthConstant;
import cn.hsw.platform.core.base.BaseController;
import cn.hsw.platform.core.dto.ResultDto;
import cn.hsw.platform.core.util.ResultUtil;
import cn.hsw.platform.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 对外 暴露的api
 * @author 李子木
 */
@RestController
public class ManageController extends BaseController {

    @Autowired
    RoleService roleService;

    @PostMapping("/auth/user")
    @AuthPermission(AuthConstant.NO_NEED_AUTHENTICATION_DEFAULT_CODE)
    public ResultDto<List<Long>> authUser(@RequestParam("user_pid")Long userPid){

        List<Long> rolePidByUserPid = roleService.findRolePidByUserPid(userPid);

        return ResultUtil.success(rolePidByUserPid);
    }

    @PostMapping("/auth/role")
    @AuthPermission(AuthConstant.NO_NEED_AUTHENTICATION_DEFAULT_CODE)
    public ResultDto<List<String>> authRole(@RequestParam("role_pid")Long rolePid){
        List<String> codeList = roleService.findPermissionCodeByRolePid(rolePid);
        return ResultUtil.success(codeList);
    }
}
